 {literal}
<script type="text/javascript">
	function clearForm(obj) {
		$(obj).find('input:[type=text]').val('');
		$(obj).find('select').val(0);
	}
</script>
{/literal}
<h1>Produkty</h1>
{if isset($filter)}{assign var=class value=colapse}{else}{assign var=class value=expand}{/if}
{mainoptions title="Filtry" class=$class}
<form method="post" >
<table cellspacing="5" cellpadding="0" border="0">
	<tr>
		<td>
			Kategoria:
		</td>
		<td>
			<select name="id_category">
				<option value="0">---</option>
				{foreach from=$categories item=category}
				{if $category->getChildren()|@count gt 0}
				<optgroup  label="{$category->getName()}">
					{foreach from=$category->getChildren() item=child}
					<option {if isset($filter.id_category) && $filter.id_category eq $child->getId()}selected="selected"{/if} value="{$child->getId()}"> - {$child->getName()}</option>
					{/foreach}
				</optgroup>
				{else}
				<option {if isset($filter.id_category) && $filter.id_category eq $category->getId()}selected="selected"{/if} value="{$category->GetId()}">{$category->getName()}</option>
				{/if}
				{/foreach}
			</select>
		</td>
		<td>
			Producent:
		</td>
		<td>
			<select name="id_manufacturer">
				<option value="0">---</option>
				{foreach from=$manufacturers item=manufacturer}<option {if isset($filter.id_manufacturer) && $filter.id_manufacturer eq $manufacturer->getId()}selected="selected"{/if} value="{$manufacturer->getId()}">{$manufacturer->getName()}</option>{/foreach}
			</select>
		</td>
	</tr>
	<tr>
		<td>
			Nazwa:
		</td>
		<td>
			<input type="text" name="name" {if isset($filter.name)}value="{$filter.name}"{/if} />
		</td>
		<td>
			Kod produktu:
		</td>
		<td>
			<input type="text" name="code" {if isset($filter.code)}value="{$filter.code}"{/if} />
		</td>
	</tr>
	<tr>
		<td colspan="4" align="center"><input type="submit" value="Filtruj" /><input onclick="clearForm(this.form);this.form.submit();" type="button" value="Czyść" /></td>
	</tr>
</table>
</form>
{/mainoptions}
{mainoptions title="Lista"}
		<table cellspacing="0" cellpadding="0" border="0">
			<tr>
				<td>{tables label="ID" tid=product_table_main o=id}</td>
				<td>{tables label="Nazwa" tid=product_table_main o=name}</td>
				<td>{tables label="Kod" tid=product_table_main o=serial}</td>
                                <td>{tables label="Cena" tid=product_table_main o=serial}</td>
				<th class="noSort"><a href="{url Product=Add}" class="add">Dodaj</a><div class="sort"><a class="ascendingAct" href="#">&nbsp;</a><a class="descending" href="#">&nbsp;</a></div></th>

			</tr>
			{foreach from=$list item=obj name=product_table_main}
			<tr>
				<td>{$obj->getId()}</td>
				<td>{$obj->getName()}</td>
				<td>{$obj->getCode()}</td>
                                <td>{$obj->productShop->getPrice()}</td>
				<td>
					<a href="{url shop=editProduct id=$obj->productShop->getId()}" class="edit"> edytuj</a>
					
					<a onclick="if(!confirm('Czy na pewno chcesz usunąć ten element?'))return false;" href="{url shop=removeProduct id=$obj->productShop->getId()}" class="delete"> usuń</a>
				</td>
			</tr>
			{/foreach}
			<tr class="selAllRow">
				<td colspan="2">
					<div class="pager">
						{tables type='pagination' tid='product_table_main' all_count=$c}
						{tables type='on_page' tid='product_table_main'}
					</div>
				</td>
			</tr>
		</table>
{/mainoptions}